package com.imooc.hadoop.mapreduce.zip;

import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;

/**
 * @program: hadoop_db
 * @description: WordsCountReducer
 * @author: zengchen
 * @create: 2021-03-28 19:20
 **/
public class ZipWcReducer extends Reducer<Text, LongWritable, Text, LongWritable> {

    Logger logger = LoggerFactory.getLogger(ZipWcReducer.class);

    @Override
    protected void reduce(Text key, Iterable<LongWritable> values, Context context) throws IOException, InterruptedException {
        logger.info("start key2 = {}, value2 = {}", key, values);
        long count = 0L;
        for (LongWritable value : values) {
            count += value.get();
        }
        logger.info("end key3 = {}, value3 = {}", key, count);
        context.write(key, new LongWritable(count));
    }
}
